package com.sys.server.modules.controller;

import com.sys.server.common.annotation.Authentication;
import com.sys.server.common.annotation.Log;
import com.sys.server.common.model.R;
import com.sys.server.modules.controller.dto.LoginDto;
import com.sys.server.modules.controller.dto.LogoutDto;
import com.sys.server.modules.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 登录模块
 *
 * @author shanbingzhen
 * @date 2022-01-10 09:48
 */
@RestController
@Api(tags = "登录模块")
@Authentication
public class LoginController {

    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "登录模块--用户登录")
    @PostMapping(value = "/login")
    public R login(@ApiParam(value = "username") @RequestBody @Validated LoginDto loginDto) {
        return loginService.login(loginDto.getUsername(), loginDto.getPassword());
    }

    @ApiOperation(value = "登录模块--退出登录")
    @GetMapping(value = "/logout")
    public R logout(@ApiParam(value = "用户token") @RequestParam String token) {
        return loginService.logout(token);
    }

}
